<%@ page language="java" %>

<%@ page import="com.scalar.chiptrack.utils.ConfigManager,
                com.scalar.chiptrack.sales.Orders"%>
<%@ page import="java.util.ArrayList" %>

<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-nested.tld" prefix="nested" %>
<%@ taglib uri="/WEB-INF/chiptrack-tags.tld" prefix="chiptrack" %>

<chiptrack:checkLogon sourcePage="/proformaInvoice.do" />

<%String chipTracContext = "/" + ConfigManager.getChipTracContext(); %>

<HTML>
<HEAD><TITLE>Scalarsoft - ChipTrac</TITLE>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<LINK href="<%=chipTracContext%>/jsp/includes/stylesheets/scalarsoft.css" type="text/css" rel="stylesheet"></HEAD>
<script src="<%=chipTracContext%>/jsp/includes/scripts/functions.js"></script>
<script src="<%=chipTracContext%>/jsp/includes/scripts/validations.js"></script>
<script src="<%=chipTracContext%>/jsp/includes/scripts/assembly_release.js"></script>
<script src="<%=chipTracContext%>/jsp/includes/scripts/quickSearch.js"></script>

<SCRIPT language="JavaScript">
window.onload=init;

function init()
{
    qs_1 = new QuickSearch(document.financeproformaInvoiceForm['searchSalesOrderId'], document.financeproformaInvoiceForm.qs1, false);
}
function searchSalesOrdersForNewProformaInvoices()
{
    var form = document.financeproformaInvoiceForm;
    var errors = ""

    if( form.searchSalesOrderId.value == "-1" )
    {
        //errors = errors + "<li>Select Sales Order No. to generate Proforma Invoice";
    }
    if( errors != "" )
    {
        var pa=document.getElementById("errors");
        pa.innerHTML = errors;
        return;
    }
    else
    {
        document.financeproformaInvoiceForm.searchWithCompulsoryFields.value = 'true';
        document.financeproformaInvoiceForm.action = '<%=chipTracContext%>/newproformaInvoice.do?action=newInvoice';
        document.financeproformaInvoiceForm.submit();
    }
}

function createNewProformaInvoice()
{
    var form                    = document.financeproformaInvoiceForm;
    var selectedLotsObj         = form.hiddenLot;
    var atleastOneLotSelected   = false;
    var errors                  = "";

    if( typeof( selectedLotsObj.length ) == "undefined" )
    {
        if( form['availableLotsList[0].selected'].checked == true )
        {
            atleastOneLotSelected = true;
        }
    }
    else
    {
        for( var i=0; i < selectedLotsObj.length; i++ )
        {
            if( form['availableLotsList[' + i + '].selected'].checked == true )
            {
                atleastOneLotSelected = true;
                break;
            }
        }
    }
    if( atleastOneLotSelected == false )
    {
        errors = "<li>Please select atleast one Lot Number";
    }
    if( errors != "" )
    {
        var pa=document.getElementById("errors");
        pa.innerHTML = errors;
        return;
    }
    else
    {
        document.financeproformaInvoiceForm.action = '<%=chipTracContext%>/proformaInvoice.do?action=new';
        document.financeproformaInvoiceForm.submit();
    }
}

function disableSelectedLots()
{
    var form                    = document.financeproformaInvoiceForm;
    var selectedLotsObj         = form.hiddenLot;
    var atleastOneLotSelected   = false;
    var errors                  = "";

    if( typeof( selectedLotsObj.length ) == "undefined" )
    {
        if( form['availableLotsList[0].removed'].checked == true )
        {
            atleastOneLotSelected = true;
        }
    }
    else
    {
        for( var i=0; i < selectedLotsObj.length; i++ )
        {
            if( form['availableLotsList[' + i + '].removed'].checked == true )
            {
                atleastOneLotSelected = true;
                break;
            }
        }
    }
    if( atleastOneLotSelected == false )
    {
        errors = "<li>Please select aleast on Lot Number to delete";
    }
    if( errors != "" )
    {
        var pa=document.getElementById("errors");
        pa.innerHTML = errors;
        return;
    }
    else
    {
        document.financeproformaInvoiceForm.removeUnnecessaryLots.value = 'true';
        document.financeproformaInvoiceForm.searchWithCompulsoryFields.value = 'true';
        document.financeproformaInvoiceForm.action = '<%=chipTracContext%>/proformaInvoice.do?action=searchNew';
        document.financeproformaInvoiceForm.submit();
    }
}

function loadTurnKeyLabel()
{
    var form = document.financeproformaInvoiceForm;
    var errors = ""

    if( errors != "" )
    {
        var pa=document.getElementById("errors");
        pa.innerHTML = errors;
        return;
    }
    else
    {
        resetFabLotsForNewReleasesTable();
        document.financeproformaInvoiceForm.turnKeySelected.value = 'true';
        document.financeproformaInvoiceForm.action = '<%=chipTracContext%>/proformaInvoice.do?action=searchNew';
        document.financeproformaInvoiceForm.submit();
    }
}

function resetFabLotsForNewReleasesTable()
{
    var form            = document.financeproformaInvoiceForm;
    var selectedLotsObj = form.hiddenLot;
    if( typeof( selectedLotsObj ) != "undefined" )
    {
        var pa = document.getElementById("fabLotsForNewReleasesTable");
        pa.innerHTML = "";
    }
}

function partNumberChanged()
{
    var turnKeyLabel = document.getElementById("turnKeyLabel");
    turnKeyLabel.innerHTML = "";

    document.financeproformaInvoiceForm.searchTurnKey.checked = false;
}        

function reset()
{
    document.financeproformaInvoiceForm.reset();
    qs_1.resetQuickSearchCntrl();
}

function showLotHistory( lotNumber )
{
    newWindow = window.open( '<%=chipTracContext%>/lotHistory.do?lotNumber=' + lotNumber,'fabLotHistory','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=no,scrollbars=yes,width=650,height=300,left=100,top=50,resizable=yes' );
    newWindow.moveTo( 100, 50 );
    newWindow.focus();
}




</SCRIPT>


<BODY bgColor="#ffffff" leftMargin="0" topMargin="0" marginheight="0" marginwidth="0">

<!-- Top Header Start-->
<%@ include file="/jsp/includes/header.jsp" %>
<!-- Top Header End-->

<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
	<TR>
    	<TD width='180' valign='top' background='<%=chipTracContext%>/jsp/includes/images/left_red_bg.gif'>
            <!-- Side Navigation start -->
            <%@ include file="/jsp/finance/finance_menu.jsp" %>
            <!-- end of the side navigations -->
        </TD>
        <TD bgcolor="#ffffff"><IMG height=9 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=8></TD>
	    <TD bgcolor="#ffffff"><IMG height=480 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=2></TD>
	    <TD valign="top" width="100%">
            <IMG height=1 src="<%=chipTracContext%>/jsp/includes/images/clear.gif" width=500 border=0>
	        <BR>
        	<html:form name="financeproformaInvoiceForm" action="/newproformaInvoice.do" method="POST" type="com.scalar.chiptrack.finance.proformainvoice.forms.financeproformaInvoiceForm" onsubmit="javascript:return false">
    		<TABLE width="100%" align="center" cellpadding="2" cellspacing="2" border="0">
                <TR>
                    <TD width="5%" align="left">&nbsp;</td>
                    <TD colspan='3' width="95%" align="left" cellpadding="2" cellspacing="2">
                        <table border="0" width="100%" align="left">
                            <TR><TD colspan="5" class="NArialW" align="center">Proforma Invoice</TD></TR>
                            <TR><TD colspan='5' align="left" class='NArialL'>&nbsp;<FONT id="errors" color='FF0000'></font></TD></TR>
                            <TR><TD colspan='5' class="NArialL"><chiptrack:errors styleClass="NArialL"/></TD></TR>
                            <TR><TD colspan='5' class="NArialL"><chiptrack:info styleClass="NArialL"/></TD></TR>
                            <TR><TD colspan='5'><IMG src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height='10'></TD></TR>
                            <tr>
                              <td width="25%">
                              <font class="NArialL">Product Name<br>(<bean:message key="label.mfgPartNumber" />)</font>
                              </td>
                              <td width="15%"><font class="NArialL" colspan=4>
                                   <html:select property="manufacturingPartNo" styleClass="txfield">
                                        <html:options collection="productList" property="value" labelProperty="label"/>
                                   </html:select>
                              </td>
                              <td width="10%">&nbsp;</td>
                              <td width="15%"><font class="NArialL">Customer</font></td>
                              <td width="15%"><font class="NArialL">
                                <html:select property="customerId" styleClass="txfield">
                                    <html:options collection="customerList" property="value" labelProperty="label"/>
                                </html:select>
                              </td>
                            </tr>
                            <tr>
                                <td width="25%" class="NArialL">Quick Search Sales Order No:</td>
                                <td width="20%" class="NArialL">
                                    <input type="text" name="qs1" class="txfield" size='26' onkeyup='quickSearch(qs_1)'>
                                </td>
                              <td width="10%">&nbsp;</td>
                              <td width="15%">&nbsp;</td>
                              <td width="15%">&nbsp;</td>
                            </tr>
                            <tr>

                                <td width="25%" class="NArialL">Sales Order No:</td>
                                <td width="20%" class="NArialL">
                                    <html:select property="searchSalesOrderId" styleClass="txfield" style="width:180px">
                                        <html:option value="-1">--Select Sales Order No--</html:option>
                                        <html:options collection="salesOrderList" property="value" labelProperty="label"/>
                                    </html:select>
                                    <input type="hidden" name="searchWithCompulsoryFields" />
                                </td>
                              <td width="10%">&nbsp;</td>
                              <td width="15%" class="NArialL">Customer PO:</td>
                              <td width="15%" class="NArialL">
                                    <html:select property="searchPONumber" styleClass="txfield" style="width:180px">
                                        <html:option value="-1">--Select Customer PO--</html:option>
                                        <html:options collection="salesOrderCustomerPOList" property="value" labelProperty="label"/>
                                    </html:select>
                                </td>
                            </tr>
                            <tr>
                            <TR><TD colspan='5'><IMG src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height='5'></TD></TR>

                            <TR><TD colspan='5'><IMG src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height='10'></TD></TR>
                            <tr>
                                <td colspan="5" align="center">
                                    <a href="javascript:searchSalesOrdersForNewProformaInvoices()" ><img border="0" src="<%=chipTracContext%>/jsp/includes/images/search.gif" width="53" height="17" onmouseover="window.status='Click to Search for Test Release';return true" onmouseout="window.status='';return true"title="Click to Search for "/></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                    <a href="javascript:reset()"><img border="0" src="<%=chipTracContext%>/jsp/includes/images/reset.gif" width="53" height="17" onmouseover="window.status='Click to Reset';return true" onmouseout="window.status='';return true" title="Click here to Reset"></a>
                                </td>
                            </tr>
                        </table>
                    </TD>
                </TR>
                <tr > <td colspan='5'>
                   
                 <%
                     int bgcount = 0;
                 %>
                <logic:present name="ordersList" >
                <table border="0" width="100%" bordercolor="#FFFFFF" align=center   >
                 <tr>
                   <td width="10%" align="center" bgcolor="#993333"><font class="NArialL"><font color="#FFFFFF">Sales Order #</font></td>
                   <td width="25%" align="center" bgcolor="#993333"><font class="NArialL"><font color="#FFFFFF">Customer Name</font></td>
                   <td width="15%" align="center" bgcolor="#993333"><font class="NArialL"><font color="#FFFFFF">Booking Date</font></td>
                   <td width="15%" align="center" bgcolor="#993333"><font class="NArialL"><font color="#FFFFFF">Actions</font></font></td>
                 </tr>
                 <tr><td colspan=5><chiptrack:errors styleClass="NArialL" /></td></tr>
                 <logic:iterate id="order" name="ordersList" type="com.scalar.chiptrack.sales.Orders">
                 <% bgcount = bgcount + 1; %>
                 <tr>
                   <td width="10%" align="center" <%if(bgcount%2==0){%> bgcolor='#DEE1E2' <% } else {%> bgcolor='#FFFFEE' <%}%>><font class="NArialL"><bean:write name="order" property="salesOrderNo"  /></font></td>
                   <td width="25%" align="left" <%if(bgcount%2==0){%> bgcolor='#DEE1E2' <% } else {%> bgcolor='#FFFFEE' <%}%>><font class="NArialL"><bean:write name="order" property="customerName" /></font></td>
                   <td width="15%" align="center" <%if(bgcount%2==0){%> bgcolor='#DEE1E2' <% } else {%> bgcolor='#FFFFEE' <%}%>><font class="NArialL"><bean:write name="order" property="bookingDate" /></font></td>
                   <td width="15%" align="center" <%if(bgcount%2==0){%> bgcolor='#DEE1E2' <% } else {%> bgcolor='#FFFFEE' <%}%>><font class="NArialL">
                    <chiptrack:restrictedLink functionality='<%=Functionality.PRO_FORMA_INVOICE%>' action='<%=User.USER_ACTION_MODIFY%>' styleClass="leftsection" href='<%=chipTracContext + "/newproformaInvoice.do?action=new&salesOrderId=" + order.getSalesOrderId() %>' onmouseover="window.status='Click to ProForma invoice ';return true" onmouseout="window.status='';return true">Proforma Invoice</chiptrack:restrictedLink>
                   </font></td>
                 </tr>
                     </logic:iterate>
                 </table>
                 </logic:present>
                 </td></tr>

        </TABLE>
	</html:form>
<!-- till here -->
<BR><BR><BR></TD>
<TD bgcolor="#ffffff"><IMG height=1 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=1></TD>
</TR>
</TABLE>

<!-- Footer starts here -->
<%@ include file="/jsp/includes/footer.jsp" %>
<!-- footer end here -->

</BODY>
</HTML>
<%--<%}catch(Exception e){ e.printStackTrace(); }%>--%>
